home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / mpeg_stat-2.2 / video.h < prev   
Encoding:
C/C++ Source or Header  |  1995-05-10  |  13.8 KB  |  359 lines

  1. /* MPEGSTAT - analyzing tool for MPEG-I video streams
  2.  * 
  3.  *  Copyright (c) 1995 The Regents of the University of California.
  4.  * All rights reserved.
  5.  *
  6.  * Technical University of Berlin, Germany, Dept. of Computer Science
  7.  * Tom Pfeifer - Multimedia systems project - pfeifer@fokus.gmd.de
  8.  *
  9.  * Jens Brettin, Harald Masche, Alexander Schulze, Dirk Schubert
  10.  *
  11.  * This program uses parts of the source code of the Berkeley MPEG player
  12.  *
  13.  * ---------------------------
  14.  *
  15.  * Copyright (c) 1993 Technical University of Berlin, Germany
  16.  *
  17.  * for the parts of the Berkeley player used:
  18.  *
  19.  * Copyright (c) 1992 The Regents of the University of California.
  20.  * All rights reserved.
  21.  *
  22.  * ---------------------------
  23.  *
  24.  * Permission to use, copy, modify, and distribute this software and its
  25.  * documentation for any purpose, without fee, and without written agreement is
  26.  * hereby granted, provided that the above copyright notices and the following
  27.  * two paragraphs appear in all copies of this software.
  28.  * 
  29.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA 
  30.  * or the Technical University of Berlin BE LIABLE TO ANY PARTY FOR
  31.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  32.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  33.  * CALIFORNIA or the Technical University of Berlin HAS BEEN ADVISED OF THE 
  34.  * POSSIBILITY OF SUCH DAMAGE.
  35.  * 
  36.  * THE UNIVERSITY OF CALIFORNIA and the Technical University of Berlin 
  37.  * SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
  38.  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  39.  * PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE 
  40.  * UNIVERSITY OF CALIFORNIA and the Technical University of Berlin HAVE NO 
  41.  * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, 
  42.  * OR MODIFICATIONS.
  43.  */
  44.  
  45. #include <stdio.h>
  46. #include <setjmp.h>
  47.  
  48. /* X11/xmd.h correctly defines INT32, etc */
  49. #ifndef XMD_H
  50. typedef int INT32;
  51. typedef short INT16;
  52. typedef char INT8;
  53. #endif
  54. typedef unsigned int UINT32;
  55. typedef unsigned short UINT16;
  56. typedef unsigned char UINT8;
  57.  
  58. /* Define Parsing error codes. */
  59.  
  60. #define SKIP_PICTURE (-10)
  61. #define SKIP_TO_START_CODE (-1)
  62. #define PARSE_OK 1
  63.  
  64. /* Define BOOLEAN, TRUE, and FALSE. */
  65.  
  66. #define BOOLEAN int
  67. #define TRUE 1
  68. #define FALSE 0
  69.  
  70. /* Initial value for max_code_types */
  71.  
  72. #define MAX_CODE_TYPES 1024 /* The code assumes this will be 1024 or larger */
  73.  
  74. /* Set ring buffer size. */
  75.  
  76. #define RING_BUF_SIZE 5
  77.  
  78. /* Macros for picture code type. */
  79.  
  80. #define I_TYPE 1
  81. #define P_TYPE 2
  82. #define B_TYPE 3
  83. #define D_TYPE 4
  84. #define SKIP_P_TYPE 5
  85. #define SKIP_B_TYPE 6
  86.  
  87. /* Start codes. */
  88.  
  89. #define SEQ_END_CODE 0x000001b7
  90. #define SEQ_START_CODE 0x000001b3
  91. #define GOP_START_CODE 0x000001b8
  92. #define PICTURE_START_CODE 0x00000100
  93. #define SLICE_MIN_START_CODE 0x00000101
  94. #define SLICE_MAX_START_CODE 0x000001af
  95. #define EXT_START_CODE 0x000001b5
  96. #define USER_START_CODE 0x000001b2
  97.  
  98. /* Macros used with macroblock address decoding. */
  99.  
  100. #define MB_STUFFING 34
  101. #define MB_ESCAPE 35
  102.  
  103. /* Lock flags for pict images. */
  104.  
  105. #define DISPLAY_LOCK 0x01
  106. #define PAST_LOCK 0x02
  107. #define FUTURE_LOCK 0x04
  108.  
  109. #define HYBRID_DITHER 0
  110. #define HYBRID2_DITHER 1
  111. #define FS4_DITHER 2
  112. #define FS2_DITHER 3
  113. #define FS2FAST_DITHER 4
  114. #define Twox2_DITHER 5
  115. #define GRAY_DITHER 6
  116. #define FULL_COLOR_DITHER 7
  117. #define NO_DITHER 8
  118. #define ORDERED_DITHER 9
  119. #define MONO_DITHER 10
  120. #define MONO_THRESHOLD 11
  121. #define ORDERED2_DITHER 12
  122. #define MBORDERED_DITHER 13
  123.  
  124. /* External declaration of row,col to zig zag conversion matrix. */
  125.  
  126. extern const int scan[][8];
  127.  
  128. /* Temporary definition of time stamp structure. */
  129.  
  130. typedef int TimeStamp;
  131.  
  132. /* Structure with reconstructed pixel values. */
  133.  
  134. typedef struct pict_image {
  135.   unsigned char *luminance;              /* Luminance plane.   */
  136.   unsigned char *Cr;                     /* Cr plane.          */
  137.   unsigned char *Cb;                     /* Cb plane.          */
  138.   unsigned char *display;                /* Display plane.     */
  139.   int locked;                            /* Lock flag.         */
  140.   TimeStamp show_time;                   /* Presentation time. */
  141.  
  142. #ifdef SH_MEM
  143.   XShmSegmentInfo shminfo;               /* Segment info.  */
  144.   XImage *ximage;                        /* Ximage struct. */
  145. #endif
  146.  
  147. } PictImage;
  148.  
  149. /* Group of pictures structure. */
  150.  
  151. typedef struct GoP {
  152.   BOOLEAN drop_flag;                     /* Flag indicating dropped frame. */
  153.   unsigned int tc_hours;                 /* Hour component of time code.   */
  154.   unsigned int tc_minutes;               /* Minute component of time code. */
  155.   unsigned int tc_seconds;               /* Second component of time code. */
  156.   unsigned int tc_pictures;              /* Picture counter of time code.  */
  157.   BOOLEAN closed_gop;                    /* Indicates no pred. vectors to
  158.                         previous group of pictures.    */
  159.   BOOLEAN broken_link;                   /* B frame unable to be decoded.  */
  160.   char *ext_data;                        /* Extension data.                */
  161.   char *user_data;                       /* User data.                     */
  162.   int  ext_size;                         /* Length of Extension data       */
  163.   int  user_size;                        /* Length of User data            */
  164.   char *code_types;                      /* char array representing picture
  165.                         coding types in display order  */
  166.   int  max_code_types;                   /* current size of code_types     */
  167.   int  picture_count;                    /* number of pictures in this GOP */
  168. } GoP;
  169.  
  170. /* Picture structure. */
  171.  
  172. typedef struct pict {
  173.   unsigned int temp_ref;                 /* Temporal reference.             */
  174.   unsigned int code_type;                /* Frame type: P, B, I             */
  175.   unsigned int vbv_delay;                /* Buffer delay.                   */
  176.   BOOLEAN full_pel_forw_vector;          /* Forw. vectors specified in full
  177.                         pixel values flag.              */
  178.   unsigned int forw_r_size;              /* Used for vector decoding.       */
  179.   unsigned int forw_f;                   /* Used for vector decoding.       */
  180.   BOOLEAN full_pel_back_vector;          /* Back vectors specified in full 
  181.                         pixel values flag.              */
  182.   unsigned int back_r_size;              /* Used in decoding.               */
  183.   unsigned int back_f;                   /* Used in decoding.               */
  184.   char *extra_info;                      /* Extra bit picture info.         */
  185.   char *ext_data;                        /* Extension data.                 */
  186.   char *user_data;                       /* User data.                      */
  187.   int  ext_size;                         /* Length of Extension data       */
  188.   int  user_size;                        /* Length of User data            */
  189. } Pict;
  190.  
  191. /* Slice structure. */
  192.  
  193. typedef struct slice {
  194.   unsigned int vert_pos;                 /* Vertical position of slice. */
  195.   unsigned int quant_scale;              /* Quantization scale.         */
  196.   char *extra_info;                      /* Extra bit slice info.       */
  197. } Slice;
  198.  
  199. /* Macroblock structure. */
  200.  
  201. typedef struct macroblock {
  202.   int mb_address;                        /* Macroblock address.              */
  203.   int past_mb_addr;                      /* Previous mblock address.         */
  204.   int motion_h_forw_code;                /* Forw. horiz. motion vector code. */
  205.   unsigned int motion_h_forw_r;          /* Used in decoding vectors.        */
  206.   int motion_v_forw_code;                /* Forw. vert. motion vector code.  */
  207.   unsigned int motion_v_forw_r;          /* Used in decdoinge vectors.       */
  208.   int motion_h_back_code;                /* Back horiz. motion vector code.  */
  209.   unsigned int motion_h_back_r;          /* Used in decoding vectors.        */
  210.   int motion_v_back_code;                /* Back vert. motion vector code.   */
  211.   unsigned int motion_v_back_r;          /* Used in decoding vectors.        */
  212.   unsigned int cbp;                      /* Coded block pattern.             */
  213.   BOOLEAN mb_intra;                      /* Intracoded mblock flag.          */
  214.   BOOLEAN bpict_past_forw;               /* Past B frame forw. vector flag.  */
  215.   BOOLEAN bpict_past_back;               /* Past B frame back vector flag.   */
  216.   int past_intra_addr;                   /* Addr of last intracoded mblock.  */
  217.   int recon_right_for_prev;              /* Past right forw. vector.         */
  218.   int recon_down_for_prev;               /* Past down forw. vector.          */
  219.   int recon_right_back_prev;             /* Past right back vector.          */
  220.   int recon_down_back_prev;              /* Past down back vector.           */
  221. } Macroblock;
  222.  
  223. /* Block structure. */
  224.  
  225. typedef struct block {
  226.   short int dct_recon[8][8];             /* Reconstructed dct coeff matrix. */
  227.   short int dct_dc_y_past;               /* Past lum. dc dct coefficient.   */
  228.   short int dct_dc_cr_past;              /* Past cr dc dct coefficient.     */
  229.   short int dct_dc_cb_past;              /* Past cb dc dct coefficient.     */
  230. } Block;
  231.  
  232. /* Video stream structure. */
  233.  
  234. typedef struct vid_stream {
  235.   unsigned int h_size;                         /* Horiz. size in pixels.     */
  236.   unsigned int v_size;                         /* Vert. size in pixels.      */
  237.   unsigned int mb_height;                      /* Vert. size in mblocks.     */
  238.   unsigned int mb_width;                       /* Horiz. size in mblocks.    */
  239.   unsigned char aspect_ratio;                  /* Code for aspect ratio.     */
  240.   unsigned char orig_picture_rate;             /* Code for picture rate 
  241.                           as it appears in the stream*/
  242.   unsigned char picture_rate;                  /* a valid picture rate       */
  243.   unsigned int bit_rate;                       /* Bit rate.                  */
  244.   unsigned int vbv_buffer_size;                /* Minimum buffer size.       */
  245.   BOOLEAN const_param_flag;                    /* Contrained parameter flag. */
  246.   unsigned char intra_quant_matrix[8][8];      /* Quantization matrix for
  247.                           intracoded frames.         */
  248.   unsigned char non_intra_quant_matrix[8][8];  /* Quanitization matrix for 
  249.                           non intracoded frames.     */
  250.   char *ext_data;                              /* Extension data.            */
  251.   char *user_data;                             /* User data.                 */
  252.   int  ext_size;                               /* Length of Extension data   */
  253.   int  user_size;                              /* Length of User data        */
  254.   GoP group;                                   /* Current group of pict.     */
  255.   Pict picture;                                /* Current picture.           */
  256.   Slice slice;                                 /* Current slice.             */
  257.   Macroblock mblock;                           /* Current macroblock.        */
  258.   Block block;                                 /* Current block.             */
  259.   int state;                                   /* State of decoding.         */
  260.   int bit_offset;                              /* Bit offset in stream.      */
  261.   unsigned int *buffer;                        /* Pointer to next byte in
  262.                           buffer.                    */
  263.   int buf_length;                              /* Length of remaining buffer.*/
  264.   unsigned int *buf_start;                     /* Pointer to buffer start.   */
  265.   int max_buf_length;                          /* Max lenght of buffer.      */
  266.   PictImage *past;                             /* Past predictive frame.     */
  267.   PictImage *future;                           /* Future predictive frame.   */
  268.   PictImage *current;                          /* Current frame.             */
  269.   PictImage *ring[RING_BUF_SIZE];              /* Ring buffer of frames.     */
  270. } VidStream;   
  271.  
  272. /* Declaration of global pointer to current video stream. */
  273.  
  274. extern VidStream *curVidStream;
  275.  
  276. /* Dither flags external declaration. */
  277. extern char *ditherFlags;
  278.  
  279. /* Definition of Contant integer scale factor. */
  280.  
  281. #define CONST_BITS 13
  282.  
  283. /* Misc DCT definitions */
  284. #define DCTSIZE        8    /* The basic DCT block is 8x8 samples */
  285. #define DCTSIZE2    64    /* DCTSIZE squared; # of elements in a block */
  286.  
  287. #define GLOBAL            /* a function referenced thru EXTERNs */
  288.   
  289. typedef short DCTELEM;
  290. typedef DCTELEM DCTBLOCK[DCTSIZE2];
  291.  
  292.  
  293. extern double realTimeStart;
  294. extern int totNumFrames;
  295.  
  296. extern unsigned int bitCount;
  297. extern int showEachFlag;
  298. extern unsigned int cacheHit[8][8];
  299. extern unsigned int cacheMiss[8][8];
  300.  
  301. /* Statistics collecting structure */
  302. typedef struct {
  303.   unsigned int frame, slice, block, size, btype, qs;
  304.   unsigned int mb_skipped, mb_coded, cblks, nblks;
  305.   int q[4][256];
  306.   int chist[6];
  307. } BlockVals;
  308.  
  309. typedef struct {
  310.   int frametype;
  311.   unsigned int totsize;
  312.   unsigned int number;
  313.   unsigned int i_mbsize;
  314.   unsigned int p_mbsize;
  315.   unsigned int b_mbsize;
  316.   unsigned int bi_mbsize;
  317.   unsigned int i_mbnum;
  318.   unsigned int p_mbnum;
  319.   unsigned int b_mbnum;
  320.   unsigned int bi_mbnum;
  321.   unsigned int i_mbcbp[64];
  322.   unsigned int p_mbcbp[64];
  323.   unsigned int b_mbcbp[64];
  324.   unsigned int bi_mbcbp[64];
  325.   unsigned int i_mbcoeff[64];
  326.   unsigned int p_mbcoeff[64];
  327.   unsigned int b_mbcoeff[64];
  328.   unsigned int bi_mbcoeff[64];
  329.   unsigned long qual;
  330.   unsigned int qnum;
  331.   double tottime;
  332. } Statval;
  333.  
  334. /* System Layer Junk */
  335. #define PACK_START_CODE             (unsigned int)0x000001ba
  336. #define SYSTEM_HEADER_START_CODE    (unsigned int)0x000001bb
  337. #define PACKET_START_CODE_MASK      (unsigned int)0xffffff00
  338. #define PACKET_START_CODE_PREFIX    (unsigned int)0x00000100
  339. #define ISO_11172_END_CODE          (unsigned int)0x000001b9
  340.  
  341. #define PACK_HEADER_SIZE 8
  342.  
  343. #define STD_AUDIO_STREAM_ID ((unsigned char) 0xb8)
  344. #define STD_VIDEO_STREAM_ID ((unsigned char) 0xb9)
  345. #define MIN_STREAM_ID_ID    ((unsigned char) 0xbc)
  346. #define RESERVED_STREAM_ID  ((unsigned char) 0xbc)
  347. #define PRIVATE_STREAM_1_ID ((unsigned char) 0xbd)
  348. #define PADDING_STREAM_ID   ((unsigned char) 0xbe)
  349. #define PRIVATE_STREAM_2_ID ((unsigned char) 0xbf)
  350. #define NOT_PACKET_ID       ((unsigned char) 0xff)
  351. #define KILL_BUFFER         ((unsigned char) 0xfe)
  352.  
  353.  
  354. #define STD_SYSTEM_CLOCK_FREQ (unsigned long)90000
  355. #define MUX_RATE_SCALE_FACTOR 50
  356.  
  357. #define MAX_STREAMS 8
  358.  
  359.